package com.treeman.api.json.marker;

import java.util.Date;

import com.treeman.marker.Marker;
import com.treeman.marker.Marker.MarkerType;
import com.treeman.user.User;

public class MarkerJson {

	private Long id;
	private String name;
	private String address;
	private String description;
	private Double longitude;
	private Double latitude;
	private String type;
	private String author;
	private Date created;

	public MarkerJson() {
	}

	public MarkerJson(Marker marker) {
		this.setId(marker.getId());
		this.name = marker.getName();
		this.address = marker.getAddress();
		this.description = marker.getDescription();
		this.longitude = marker.getLongitude();
		this.latitude = marker.getLatitude();
		this.type = marker.getType().toString();
		this.author = marker.getAuthor().getUsername();
		this.created = marker.getCreated();
	}

	public MarkerJson(Long id, String name, String address, String description,
			Double longitude, Double latitude, String type, String author) {
		this.id = id;
		this.name = name;
		this.address = address;
		this.description = description;
		this.longitude = longitude;
		this.latitude = latitude;
		this.type = type;
		this.author = author;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Double getLongitude() {
		return longitude;
	}

	public void setLongitude(Double longitude) {
		this.longitude = longitude;
	}

	public Double getLatitude() {
		return latitude;
	}

	public void setLatitude(Double latitude) {
		this.latitude = latitude;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public Marker toMarker(User user) {
		Marker marker = new Marker();
		marker.setAddress(address);
		marker.setAuthor(user);
		marker.setDescription(description);
		marker.setLatitude(latitude);
		marker.setLongitude(longitude);
		marker.setName(name);
		if (type != null)
			marker.setType(MarkerType.valueOf(type));

		marker.setCreated(created);
		return marker;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}
}
